<?php

namespace AppBundle\Controller;

use AdminBundle\Entity\HuobiSwitchLog;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use AppBundle\Task\AlertModelConfig;
/**
 * HuobiKlineTrack controller.
 *
 * @Route("/huobi")
 */
class HuobiKlineTrackController extends Controller
{
    /**
     * 模型-empty
     * @Route("/empty", name="huobi_calc_kline_1min_empty")
     */
    public function emptyAmazingAction(Request $request)
    {
        return $this->render('HuobiKlineTrack/track.html.twig', [
            'data' => [],
            'title' => 'empty',
            'prefix' => 'empty',
        ]);

    }

    /**
     * 模型-1.0-(拉升)
     * @Route("/track", name="huobi_calc_kline_1min_track")
     */
    public function trackAmazingAction(Request $request)
    {
        return $this->getModel($request, 'app.task.alert_model1.0');
    }

    /**
     * 模型-1.1-(拉升早期)
     * @Route("/test", name="huobi_calc_kline_amazing_test")
     */
    public function testAmazingAction(Request $request)
    {
        return $this->getModel($request, 'app.task.alert_model1.1');
    }

    /**
     * 模型-2.0-(U型)
     * @Route("/test1", name="huobi_calc_kline_amazing_test1")
     */
    public function test1AmazingAction(Request $request)
    {
        return $this->getModel($request, 'app.task.alert_model2.0');
    }

    /**
     * 模型-2.1-(急跌)
     * @Route("/test2", name="huobi_calc_kline_amazing_test2")
     */
    public function test2AmazingAction(Request $request)
    {
        return $this->getModel($request, 'app.task.alert_model2.1');
    }

    /**
     * 模型-2.2-(急跌反弹)
     * @Route("/test3", name="huobi_calc_kline_amazing_test3")
     */
    public function test3AmazingAction(Request $request)
    {
        return $this->getModel($request, 'app.task.alert_model2.2');
    }

    /**
     * 模型-2.3-(急跌反弹)
     * @Route("/test23", name="huobi_calc_kline_amazing_test23")
     */
    public function test23AmazingAction(Request $request)
    {
        return $this->getModel($request, 'app.task.alert_model2.3');
    }

    /**
     * 模型-2.7-(急跌反弹)
     * @Route("/test27", name="huobi_calc_kline_amazing_test27")
     */
    public function test27AmazingAction(Request $request)
    {
        return $this->getModel($request, 'app.task.alert_model2.7');
    }

    /**
     * 模型-2.8-(急跌反弹)
     * @Route("/test28", name="huobi_calc_kline_amazing_test28")
     */
    public function test28AmazingAction(Request $request)
    {
        return $this->getModel($request, 'app.task.alert_model2.8');
    }

    /**
     * 模型-5.9-(急跌反弹)
     * @Route("/test59", name="huobi_calc_kline_amazing_test59")
     */
    public function test59AmazingAction(Request $request)
    {
        return $this->getModel($request, 'app.task.alert_model5.9');
    }

    /**
     * 模型-6.0-(急跌反弹)
     * @Route("/test60", name="huobi_calc_kline_amazing_test60")
     */
    public function test60AmazingAction(Request $request)
    {
        return $this->getModel($request, 'app.task.alert_model6.0');
    }

    /**
     * 模型-3.0-(赚)
     * @Route("/test30", name="huobi_calc_kline_amazing_test30")
     */
    public function test30AmazingAction(Request $request)
    {
        return $this->getModel($request, 'app.task.alert_model3.0');
    }

    /**
     * 模型-3.1-(赚)
     * @Route("/test31", name="huobi_calc_kline_amazing_test31")
     */
    public function test31AmazingAction(Request $request)
    {
        return $this->getModel($request, 'app.task.alert_model3.1');
    }

    /**
     * 模型-3.3-(赚)
     * @Route("/test33", name="huobi_calc_kline_amazing_test33")
     */
    public function test33AmazingAction(Request $request)
    {
        return $this->getModel($request, 'app.task.alert_model3.3');
    }

    /**
     * 模型-3.4-(赚)
     * @Route("/test34", name="huobi_calc_kline_amazing_test34")
     */
    public function test34AmazingAction(Request $request)
    {
        return $this->getModel($request, 'app.task.alert_model3.4');
    }

    /**
     * 模型-3.5-(赚)
     * @Route("/test35", name="huobi_calc_kline_amazing_test35")
     */
    public function test35AmazingAction(Request $request)
    {
        return $this->getModel($request, 'app.task.alert_model3.5');
    }

    /**
     * 模型-7.1-(futures)
     * @Route("/test71", name="huobi_calc_kline_amazing_futrues71")
     */
    public function futures71AmazingAction(Request $request)
    {
        return $this->getModel($request, 'app.task.alert_model7.1');
    }

    /**
     * 模型-7.2-(futures)
     * @Route("/test72", name="huobi_calc_kline_amazing_futrues72")
     */
    public function futures72AmazingAction(Request $request)
    {
        return $this->getModel($request, 'app.task.alert_model7.2');
    }

    /**
     * 终端显示页面
     * @Route("/cross", name="huobi_calc_kline_cross")
     */
    public function crossAction(Request $request)
    {
        $length = $request->query->getInt('length', 20);
        $duration = $request->query->getInt('duration', 720);
        $coin = $request->query->get('coin', '');

        $pages = [
            'one' => 'huobi_calc_kline_track_1_2',
            'two' => 'huobi_calc_kline_amazing_test35',
            'three' => 'huobi_calc_kline_amazing_test23',
            'four' => 'huobi_calc_kline_amazing_test30'
        ];

        return $this->render('HuobiKlineTrack/cross_pattern.html.twig', [
            'pages' => $pages,
        ]);
    }

    /**
     * 跟踪-1.0
     * @Route("/track1_0", name="huobi_calc_kline_track_1_0")
     */
    public function track1_0amazingAction(Request $request)
    {
        return $this->getModel($request, 'app.task.alert_model3.2');
    }

    /**
     * 跟踪-1.1
     * @Route("/track1_1", name="huobi_calc_kline_track_1_1")
     */
    public function track1_1amazingAction(Request $request)
    {
        return $this->getModel($request, 'app.task.alert_model2.4');
    }

    /**
     * 跟踪-1.2
     * @Route("/track1_2", name="huobi_calc_kline_track_1_2")
     */
    public function track1_2amazingAction(Request $request)
    {
        return $this->getModel($request, 'app.task.alert_model2.5');
    }

    /**
     * 跟踪-1.3
     * @Route("/track1_3", name="huobi_calc_kline_track_1_3")
     */
    public function track1_3amazingAction(Request $request)
    {
        return $this->getModel($request, 'app.task.alert_model2.6');
    }

    /**
     * 终端显示页面
     * @Route("/cross1", name="huobi_calc_kline_cross1")
     */
    public function cross1Action(Request $request)
    {
        $length = $request->query->getInt('length', 20);
        $duration = $request->query->getInt('duration', 720);
        $coin = $request->query->get('coin', '');

        $pages = [
            'one' => 'huobi_calc_kline_track_1_1',
            'two' => 'huobi_calc_kline_track_1_3',
            'three' => 'huobi_calc_kline_amazing_test31',
            'four' => 'huobi_calc_kline_track_1_0'
        ];

        return $this->render('HuobiKlineTrack/track_cross_pattern.html.twig', [
            'pages' => $pages,
        ]);
    }

    private function getModel(Request $request, $service)
    {
        $length = $request->query->getInt('length', 20);
        $duration = $request->query->getInt('duration', 360);
        $coin = $request->query->get('coin', '');

        $options = ['length' => $length, 'duration' => $duration, 'coin' => $coin];

        $alert_model = $this->get($service);

        return $this->render('HuobiKlineTrack/track.html.twig', [
            'data' => $alert_model->process($options),
            'title' => $alert_model->title(),
            'prefix' => $alert_model->prefix(),
            'reportTypes' => AlertModelConfig::tradeTypes(),

        ]);
    }



//    /**
//     * 终端显示页面
//     * @Route("/status", name="huobi_calc_kline_status")
//     */
//    public function statusAction(Request $request)
//    {
//        $data = [];
//        $class = new \ReflectionClass($this);
//
//        $regex = '/([\x{4e00}-\x{9fa5}]+\S+).+name="(.+)"/usix'; // -u:unicode(utf-8);-s:single line; -i: ignore case; -x:strip blank char;
//        foreach ($class->getMethods(\ReflectionProperty::IS_PUBLIC) as $method) {
//            if (strpos($method->getName(), 'Amazing') === false)
//                continue;
//
//            if (preg_match($regex, $method->getDocComment(), $match)) {
//                $r = clone $request;
//                $r->attributes->set('_route', $match[2]);
//                list($is_pause, $_) = $this->isPause($r);
//                $match[3] = $is_pause;
//
//                $data [] = $match;
//            }
//
//        }
//
//        return $this->render('HuobiKlineTrack/status.html.twig', [
//            'data' => $data,
//            'title' => '状态查看'
//        ]);
//    }
}
